package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Exam;
import cn.wolfcode.domain.Question;
import cn.wolfcode.mapper.ExamMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IExamService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExamServiceImpl implements IExamService {

    @Autowired
    private ExamMapper examMapper;

    @Override
    public void save(Exam exam) {
        examMapper.insert(exam);
    }

    @Override
    public void delete(Long id) {
        examMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(Exam exam) {
        examMapper.updateByPrimaryKey(exam);
    }

    @Override
    public Exam get(Long id) {
        return examMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Exam> listAll() {
        return examMapper.selectAll();
    }

    @Override
    public PageInfo<Exam> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize()); //对下一句sql进行自动分页
        List<Exam> exams = examMapper.selectForList(qo); //里面不需要自己写limit
        return new PageInfo<Exam>(exams);
    }

    @Override
    public Long selectBytitle(String title) {
        return  examMapper.selectBytitle(title);
    }

    @Override
    public void insertRelation(Long id, Question randomEle, Integer score, int i) {
        examMapper.insertRelation(id,randomEle,score,i);
    }

    @Override
    public List<Exam> selectByExam(Long id) {
        return examMapper.selectByExam(id);
    }

    @Override
    public List<Exam> selectAnswer(Long id) {
        return examMapper.selectAnswer(id);
    }

    @Override
    public List<Exam> selectTrueAnswer(Long id) {
        return examMapper.selectTrueAnswer(id);
    }


}
